using Microsoft.EntityFrameworkCore;
using CarRentalSystem.Controllers;
using CarRentalSystem.Dtos;
using AutoMapper;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(c=>c.AddPolicy("any",p=>p.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod()));
// Add services to the container.


builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

//builder.Services.AddAutoMapper(typeof(CarForCreateDto));
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

var configuration = builder.Configuration;
builder.Services.AddDbContext<CarContext>(option=>{
    option.UseSqlServer(configuration.GetConnectionString("Default"));
});



var app = builder.Build();


// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();
app.UseCors("any");
app.MapControllers();

app.Run();
